package com.xc.hotelmgr.webapi.modules.dt.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xc.hotelmgr.webapi.common.utils.PageUtils;
import com.xc.hotelmgr.webapi.common.utils.Query;

import com.xc.hotelmgr.webapi.modules.dt.dao.StoreDao;
import com.xc.hotelmgr.webapi.modules.dt.entity.StoreEntity;
import com.xc.hotelmgr.webapi.modules.dt.service.StoreService;


@Service("storeService")
public class StoreServiceImpl extends ServiceImpl<StoreDao, StoreEntity> implements StoreService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<StoreEntity> page  = new Query<StoreEntity>().getPage(params);
        List<StoreEntity> list = baseMapper.queryPage(page,params.get("dtId"));
        PageUtils pageUtils = new  PageUtils(page,list);
        return pageUtils;
    }

    @Override
    public StoreEntity queryById(Integer id) {
        return  baseMapper.queryById(id);
    }

    @Override
    public  List<StoreEntity> queryByDtId(Map<String, Object> params) {
        Object dtId = params.get("dtId");
        Object pf = params.get("pf");
        String inSql = "SELECT id FROM dt_dt WHERE FIND_IN_SET(id, getChild(" + dtId + "))";
        List<StoreEntity> list = baseMapper.selectList(new QueryWrapper<StoreEntity>()
                .eq(pf != null, "blon_plantform", pf)
                .inSql(dtId != null, "dt_id", inSql));
        return list;
    }

    @Override
    public  List<StoreEntity> sqlSelectByDtPf(Map<String, Object> params) {
        List<StoreEntity> list = this.baseMapper.sqlSelectByDtPf(params);
        return list;
    }

    @Override
    public List<StoreEntity> selectByDt(Integer dtId) {
        return baseMapper.selectByDtId(dtId);
    }

}